package it.controllocredito.frontend.fragments.params;

import it.controllocredito.R;
import it.controllocredito.backend.persistence.bean.Soglia.FrequenzaEnum;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class PhoneParamsTabFragment extends Fragment
{
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup group,
			Bundle saved)
	{
		return inflater.inflate(R.layout.phone_params_tab_fragment, group, false);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState)
	{
		super.onActivityCreated(savedInstanceState);
		
		Spinner spnrFrequenza = (Spinner) getActivity().findViewById(R.id.spnr_frequenza);
		// Create an ArrayAdapter using the string array and a default spinner layout
		ArrayAdapter<CharSequence> adapterFrequenza = ArrayAdapter.createFromResource(getActivity(),
		        R.array.frequenza_array, android.R.layout.simple_spinner_item);
		// Specify the layout to use when the list of choices appears
		adapterFrequenza.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// Apply the adapter to the spinner
		spnrFrequenza.setAdapter(adapterFrequenza);
		
		final Spinner spnrGiorniSettimana = (Spinner) getActivity().findViewById(R.id.spnr_giorni_settimana);
		ArrayAdapter<CharSequence> adapterGiorni = ArrayAdapter.createFromResource(getActivity(), 
				R.array.giorni_settimana_array, android.R.layout.simple_spinner_item);
		adapterGiorni.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
		spnrGiorniSettimana.setAdapter(adapterGiorni);

		spnrFrequenza.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
			public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
				EditText editGiornoMese = (EditText)getActivity().findViewById(R.id.edtxt_giorno_mese);
				   if(pos==FrequenzaEnum.GIORNO.ordinal()){
		    	   editGiornoMese.setVisibility(View.GONE);
		    	   spnrGiorniSettimana.setVisibility(View.VISIBLE);
		    	   } else if(pos==FrequenzaEnum.MESE.ordinal()){
		    		   editGiornoMese.setVisibility(View.VISIBLE);
			    	   spnrGiorniSettimana.setVisibility(View.GONE);
		    	   }
		    }
		    public void onNothingSelected(AdapterView<?> parent) {
		    }
		});
		
		final Button button = (Button) getActivity().findViewById(R.id.btn_phone_params);
		button.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Toast.makeText(getActivity(),
						"You clicked button on Prova Fragment",
						Toast.LENGTH_LONG).show();
			}
		});
	}
	
}